import axios from "axios";
//import store from "@/store";

const http = axios.create({
  //baseURL: process.env.PROJECT_NAME == "online"  ? "http://top.shenghui56.com:8088/" : "http://192.168.10.94:13000/",//请求地址==> 测试,
  baseURL: process.env.PROJECT_NAME === "online"  ? "http://top.shenghui56.com:8088/" : "http://172.29.16.174:12000/",//请求地址==> 许莎,
  timeout: 100000,
  headers: {
    'Content-Type': 'application/json;charset=UTF-8'
  },
  transformRequest: [function (data) {
    return JSON.stringify(data||'');
  }],
});

// http request拦截器 添加一个请求拦截器
http.interceptors.request.use(
  function(config) {
    let token = window.localStorage.getItem("httpToken") || "";
    if (token && config.url.indexOf("/index/getSignature.do") === -1) {
      config.headers.httptoken = token;
    }
    return config;
  },
  function(error) {
    return Promise.reject(error);
  }
);

//响应拦截
http.interceptors.response.use(
  async (res) => {
    return res.data
  },
  (err) => {
    throw new Error(err)
  }
);



export default http;
